package org.ros.android.android_tutorial_image_transport;

import org.ros.node.AbstractNodeMain;

import org.ros.concurrent.CancellableLoop;
import org.ros.namespace.GraphName;
import org.ros.node.ConnectedNode;
import org.ros.node.topic.Publisher;

import static java.lang.Thread.sleep;

/**
 * Created by corvin on 17-8-7.
 */

public class TextToSpeaker extends AbstractNodeMain
{
    private String topic_name;

    public TextToSpeaker() {
        this.topic_name = "/voice/xf_tts_topic";
    }

    public GraphName getDefaultNodeName() {
        return GraphName.of("TextToSpeaker");
    }

    public void onStart(ConnectedNode connectedNode)
    {
        final Publisher<std_msgs.String> publisher = connectedNode.newPublisher(this.topic_name, "std_msgs/String");
        connectedNode.executeCancellableLoop(new CancellableLoop()
        {
            protected void setup() {            }

            protected void loop() throws InterruptedException
            {
                if(MainActivity.sendTTSFlag )
                {
                    std_msgs.String cmd = publisher.newMessage();
                    cmd.setData(MainActivity.sendText);
                    publisher.publish(cmd);
                }
                MainActivity.sendTTSFlag = false;
                sleep( 100 );
            }
        });
    }
}